<include file="Public:header_content" />


<link href="/Public/plugin/gb312/css/plugins/summernote/summernote.css"  rel="stylesheet">
<link href="/Public/plugin/gb312/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
<div class="wrapper wrapper-content">


        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5><{$data.article_name}></h5>
                        <button id="edit" class="btn btn-primary btn-xs m-l-sm"  type="button">编辑</button>
                        <button id="save" class="btn btn-primary  btn-xs" type="button">保存</button>
                        <button id="reset" class="btn btn-primary  btn-xs" type="button">重置</button>
                        <div class="ibox-tools">
                            <a class="back-link" href="javascript:history.go(-1);">
                                <i class="fa fa-chevron-left"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content" id="eg">
                            <div id="summernote" class="click2edit wrapper"><{$content|html_entity_decode}></div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <input type="hidden" name="article_id" value="<{$article_id}>" />
    <input type="hidden" name="pathFile" value="<{$data.content}>" />
<include file="Public:footer_content" />
    <script src="/Public/plugin/gb312/js/plugins/summernote/summernote.min.js" ></script>
    <script src="/Public/plugin/gb312/js/plugins/summernote/summernote-zh-CN.js" ></script>
    <script type="text/javascript">


        $('#edit').click(function(){
            $("#eg").addClass("no-padding");
            $(".click2edit").summernote({
                lang:"zh-CN",
                focus:true,
                onImageUpload: function(files,editor, welEditable) {
                         sendFile(files[0],editor, welEditable);
                }
            });
        });

        $('#reset').click(function(){
            $(".click2edit").summernote('reset');
            $(".click2edit").summernote('disable');
        });

        $('#save').click(function(){
            content=$(".click2edit").code();
            article_id = $('input[name="article_id"]').val();
            $.ajax({
                type: "post",
                url: '<{:U("Book/updateContent")}>',
                data: 'pathFile=<{$data.content}>&article_id='+article_id+'&content='+encodeURIComponent(content),
                success: function(msg){
                    if(msg == 'success'){
                            $("#eg").removeClass("no-padding");
                            $(".click2edit").destroy();
                            swal("已成功保存","","success");
                      }else{
                            swal("保存失败","","error");
                      }
                }
             });
        });
function trim(str){ //删除左右两端的空格
	     return str.replace(/(^\s*)|(\s*$)/g,"");
}
        function sendFile(file,editor,welEditable) {
            formData = new FormData();
            formData.append("file", file);
            //console.log(formData);
            $.ajax({
                url: "<{:U('Public/UploadImg')}>",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                success: function(url) {
                      editor.insertImage(welEditable, url);
                }
            });
        }

        $(".click2edit").destroy()
</script>